package com.ego.ware.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ego.common.util.PageUtil;
import com.ego.common.vo.PageVo;
import com.ego.ware.vo.WareInfoSearchVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.ego.ware.dao.WareInfoDao;
import com.ego.ware.po.WareInfo;
import com.ego.ware.service.WareInfoService;

/**
 * @program: ego
 * @description 仓库信息对应实现类
 * @author KamTang
 * @date 2022-11-13 13:30:29
 */
@Service("wareInfoService")
public class WareInfoServiceImpl extends ServiceImpl<WareInfoDao, WareInfo> implements WareInfoService {
    @Override
    public PageVo<WareInfo> search(WareInfoSearchVo search) {
        LambdaQueryWrapper<WareInfo> query = Wrappers.lambdaQuery();
        if (StringUtils.isNotEmpty(search.getKeyword())) {
            query.like(WareInfo::getId, search.getKeyword())
                    .or().like(WareInfo::getAddress, search.getKeyword())
                    .or().like(WareInfo::getAreaCode, search.getKeyword())
                    .or().like(WareInfo::getName, search.getKeyword());
        }
        Page<WareInfo> page = this.baseMapper.selectPage(Page.of(search.getPageNum(), search.getPageSize()), query);
        return PageUtil.toPage(page);
    }
}
